package com.example.intentac;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.TextureView;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    Button btn;
    TextView textView;
    int i = 30;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initevents();
    }

    private void initView() {
        btn = findViewById(R.id.button);
        textView = findViewById(R.id.textView2);
textView.setText("你已经来过了");
        textView.setTextSize(i++);
        btn.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        Intent intent = new Intent(MainActivity.this, SecondActivity.class);
        intent.putExtra("name", "我是第一个页面");
//        startActivity(intent);
        /**
         *  startActivityForResult()方法用于当开启的Activity销毁时从中返回数据
         *  意图和请求码
         */
        startActivityForResult(intent, 1);
    }

    private void  initevents(){
        Intent intent = getIntent();
//        String firstSrt = intent.getStringExtra("name");
//        textView.setText(firstSrt);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode==1&&resultCode==2){
            String backStr = data.getStringExtra("data");
            textView.setText(backStr);
        }
    }
}
